/*
 * mana (compiler)
 * Copyright (c) 2003 Shun Moriya <shun@mnu.sakura.ne.jp>
 *
 * The MIT License
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
 * THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */

#if !defined(___MANA_MAIN_H___)
#define ___MANA_MAIN_H___

#if defined(_LANGUAGE_C_PLUS_PLUS) || defined(__cplusplus) || defined(c_plusplus)
extern "C" {
#endif

#if !defined(___MANA_DATALINK_H___)
#include "../library/mana_datalink.h"
#endif
#if !defined(___MANA_HASH_H___)
#include "../library/mana_hash.h"
#endif
#if !defined(___MANA_INFO_H___)
#include "../library/mana_info.h"
#endif
#if !defined(___MANA_MALLOC_H___)
#include "../library/mana_malloc.h"
#endif
#if !defined(___MANA_POOL_H___)
#include "mana_pool.h"
#endif

#if !defined(MANA_TRUE)
#define MANA_TRUE 1
#endif

#if !defined(MANA_FALSE)
#define MANA_FALSE 0
#endif

#if !defined(MANA_NIL)
#define MANA_NIL 0
#endif

#if !defined(_MAX_PATH)
#define _MAX_PATH 260
#endif

#if !defined(_MAX_DRIVE)
#define _MAX_DRIVE 3
#endif

#if !defined(_MAX_DIR)
#define _MAX_DIR 256
#endif

#if !defined(_MAX_FNAME)
#define _MAX_FNAME 256
#endif

#if !defined(_MAX_EXT)
#define _MAX_EXT 256
#endif

#if !defined(_MSC_VER)
#define _chdir	chdir
#define _getcwd	getcwd
extern void _makepath(char *, char *, char *, char *, char *);
extern void _splitpath(char *, char *, char *, char *, char *);
extern char* _fullpath(char *, char *, int);
#endif

#include <assert.h>
#include <stdio.h>
#include <stdlib.h>

#if defined(_DEBUG)
extern void mana_print_debug(const char* format, ...);
#define mana_print	mana_print_debug
#define mana_trace	mana_print_debug
#else
#define mana_print	printf
#define mana_trace 1 ? (void)0 : printf
#endif

#define MANA_ASSERT_MESSAGE(e, m) if(!(e)){ mana_print("%s(%d): BUG!: %s\n", __FILE__, __LINE__, m); abort(); }
#define MANA_BUG(m) { mana_print("%s(%d): BUG!: %s\n", __FILE__, __LINE__, m); abort(); }
#define MANA_SAFE_FREE(p) if(p){ free(p); p = 0; }

/* external functions */
extern void mana_error(char*, int, char* format, ...);
extern void mana_compile_error(char*, ...);
extern void mana_compile_warning(char*, ...);
extern void mana_linker_error(char*, ...);
extern void mana_linker_warning(char*, ...);
extern void mana_fatal(char*, ...);
extern void mana_fatal_no_memory(void);

extern int yyparse(void);
extern void yyerror(char*);
extern void mana_parser_initialize(void);
extern void mana_parser_finalize(void);


extern int yylex(void);
extern int mana_lexer_initialize(char*);
extern void mana_lexer_finalize(void);
extern int mana_lexer_open(char*, int);
extern int mana_lexer_close(void);
extern char* mana_lexer_get_current_filename(void);
extern int mana_lexer_get_current_line(void);

extern void mana_compile_init(void);
extern void mana_compile_exit(void);
extern int mana_compile(char*, char*);

extern void mana_output_global_memory_map(char*);

/* external variables */
extern int mana_debug;
extern int mana_release;
extern FILE* mana_variable_header_file;

extern int yynerrs;
extern FILE* yyin;
extern FILE* yyout;

#if defined(_LANGUAGE_C_PLUS_PLUS) || defined(__cplusplus) || defined(c_plusplus)
}
#endif

#endif
